/***************************************************************************

-------------------
    begin                : 
    copyright            : kuzkok
    email                : kuzkok at gmail.com

***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*   
*   Данная программа является свободным программным обеспечением;         *
*   Вы можете распространять ее и/или модифицировать в соответствии с     *
*   GNU General Public License опубликованной Фондом свободного           *
*   программного обеспечения; используемая версия лицензии - 2 или        *
*   (по вашему выбору) любая более поздняя                                *
***************************************************************************/

#include "linelooppassport.h"

LineLoopPassport::LineLoopPassport() :
        NonFacilityObject(QString("linelooppassport"))
{
}

LineLoopPassport::LineLoopPassport(QUuid theEventID) :
        NonFacilityObject(theEventID, QString("linelooppassport"))
{
    loadValues();
}

LineLoopPassport::LineLoopPassport(QString whereClause) :
        NonFacilityObject(QString("linelooppassport"), whereClause)
{
    loadValues();
}

void LineLoopPassport::loadValues()
{
    if(mObjectState)
    {
        mLineLoopEventID = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("lineloopeventid")).toString());
        mProductByPassport = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("productbypassport")).toString());
        mCategory = mSelectQuery->value(mSelectQuery->record().indexOf("category")).toString();
        mPurpose = mSelectQuery->value(mSelectQuery->record().indexOf("purpose")).toString();
        mRegisterNumber = mSelectQuery->value(mSelectQuery->record().indexOf("registernumber")).toString();
        mLength = mSelectQuery->value(mSelectQuery->record().indexOf("length")).toDouble();
        mLengthBySurvey = mSelectQuery->value(mSelectQuery->record().indexOf("lengthbysurvey")).toDouble();
        mTemperatureByPassport = mSelectQuery->value(mSelectQuery->record().indexOf("temperaturebypassport")).toDouble();
        mPressureByPassport = mSelectQuery->value(mSelectQuery->record().indexOf("pressurebypassport")).toDouble();
    }
}

void LineLoopPassport::buildInsertStatement()
{
    NonFacilityObject::buildInsertStatement();
    mInsertStatementFields += ", lineloopeventid"
                              ", productbypassport"
                              ", category"
                              ", registernumber"
                              ", purpose"
                              ", length"
                              ", lengthbysurvey"
                              ", temperaturebypassport"
                              ", pressurebypassport";
    mInsertStatementValues += ", :lineloopeventid"
                              ", :productbypassport"
                              ", :category"
                              ", :registernumber"
                              ", :purpose"
                              ", :length"
                              ", :lengthbysurvey"
                              ", :temperaturebypassport"
                              ", :pressurebypassport";
}

void LineLoopPassport::buildUpdateStatement()
{
    NonFacilityObject::buildUpdateStatement();
    mUpdateStatement += ", lineloopeventid = :lineloopeventid"
                        ", productbypassport = :productbypassport"
                        ", category = :category"
                        ", registernumber = :registernumber"
                        ", purpose = :purpose"
                        ", length = :length"
                        ", lengthbysurvey = :lengthbysurvey"
                        ", temperaturebypassport = :temperaturebypassport"
                        ", pressurebypassport = :pressurebypassport";
}

void LineLoopPassport::bindQueryValues(QSqlQuery &query)
{
    NonFacilityObject::bindQueryValues(query);
    query.bindValue(":lineloopeventid", UuidToVariant(mLineLoopEventID));
    query.bindValue(":productbypassport", UuidToVariant(mProductByPassport));
    query.bindValue(":category", mCategory);
    query.bindValue(":registernumber", mRegisterNumber);
    query.bindValue(":purpose", mPurpose);
    query.bindValue(":length", mLength);
    query.bindValue(":lengthbysurvey", mLengthBySurvey);
    query.bindValue(":temperaturebypassport", mTemperatureByPassport);
    query.bindValue(":pressurebypassport", mPressureByPassport);
}
